import { Controller, Get, Response } from '@nestjs/common';
import { AppService } from './app.service';
import { Response as Rs } from 'express';
import { ExcelServiceService } from './excel.service/excel.service.service';
@Controller()
export class AppController {
  constructor(
    private readonly appService: AppService,
    private readonly exportExcelService: ExcelServiceService,
  ) {}

  @Get()
  async getHello(@Response() res: Rs): Promise<void> {
    const { titles, vals } = await this.appService.getHtml();
    const result = this.exportExcelService.exportExcel(titles, vals);
    res.setHeader(
      'Content-Type',
      'application/vnd.openxmlformats;charset=utf-8',
    );
    res.setHeader(
      'Content-Disposition',
      'attachment; filename=' + encodeURIComponent('文件') + '.xlsx',
    ); // 中文名需要进行url转码
    res.setTimeout(30 * 60 * 1000); // 防止网络原因造成超时。
    res.end(result, 'binary');
    // return this.appService.getHello();
  }
}
